package com.maiji.cloud.controller.login;

import com.maiji.cloud.controller.BaseController;
import com.maiji.cloud.request.BaseDataReqDto;
import com.maiji.cloud.request.login.*;
import com.maiji.cloud.response.BaseDataResDto;
import com.maiji.cloud.response.BaseResDto;
import com.maiji.cloud.response.login.AppUserResData;
import com.maiji.cloud.utils.Unlogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = {"登录模块"})
public class LoginController extends BaseController {

    @Unlogin
    @ApiOperation(value = "验证手机号是否已注册")
    @PostMapping("/checkLogon")
    public BaseResDto checkLogon (@RequestBody BaseDataReqDto<String> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/checkLogon", baseDataReqDto, BaseResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "注册")
    @PostMapping("/logon")
    public BaseDataResDto<String> logon (@RequestBody BaseDataReqDto<AppUserLogonReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/logon", baseDataReqDto, BaseDataResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "登录：1-手机号密码登录，2-手机号验证码登录，3-第三方登录")
    @PostMapping("/login")
    public BaseDataResDto<String> login (@RequestBody BaseDataReqDto<AppUserLoginReqData> BaseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/login", BaseDataReqDto, BaseDataResDto.class);
    }

    @ApiOperation(value = "登出")
    @PostMapping("/logout")
    public BaseResDto logout (@RequestHeader("maijiToken") String maijiToken) {
        return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/logout", null, BaseResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "第三方登录后绑定手机号")
    @PostMapping("/bindTel")
    public BaseDataResDto<AppUserResData> bindTel (@RequestBody BaseDataReqDto<AppUserBindTelReqData> baseDataReqDto) {
        return restTemplate.postForObject(REST_URL_APPLOGIN + "/bindTel", baseDataReqDto, BaseDataResDto.class);
    }

    @Unlogin
    @ApiOperation(value = "忘记密码或修改密码")
    @PostMapping("/updatePwd")
    public BaseDataResDto<String> updatePwd (@RequestBody BaseDataReqDto<AppUserUpdatePwdReqData> baseDataReqDto,
                                             @RequestHeader(name = "maijiToken", required = false) String maijiToken) {
        return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/updatePwd", baseDataReqDto, BaseDataResDto.class);
    }

    @ApiOperation(value = "修改手机号")
    @PostMapping("/updateTel")
    public BaseDataResDto<String> updateTel (@RequestBody BaseDataReqDto<AppUserUpdateTelReqData> baseDataReqDto,
                                  @RequestHeader("maijiToken") String maijiToken) {
        return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/updateTel", baseDataReqDto, BaseDataResDto.class);
    }
    
    /**
	 * 校验登录密码是否正确
	 * 
	 * @param param
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("/checkLoginPassWord")
	@ApiOperation(value = "校验登录密码是否正确")
	public BaseDataResDto<Boolean> checkLoginPassWord(@RequestBody BaseDataReqDto<String> param,
			@RequestHeader("maijiToken") String maijiToken) {

		 return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/checkLoginPassWord", param, BaseDataResDto.class);

	}

	/**
	 * 注销账户
	 * @param maijiToken
	 * @return
	 */
	@PostMapping("/logoutAccount")
	@ApiOperation(value = "注销账户")
	public BaseResDto logoutAccount(@RequestBody BaseDataReqDto<String> param,@RequestHeader("maijiToken") String maijiToken){
		
		 return postForObjectWithToken(maijiToken,REST_URL_APPLOGIN + "/logoutAccount", param, BaseResDto.class);
	}

}
